package com.awspaas.user.apps.cpq.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.cpq.util.RefreshDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshModulDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshTempDataUtils;

public class CPQ_PorpertiesRefreshPriceWeb {

	public String porpertiesRefreshPrice(UserContext userContext, String rowData) {
		try {
			JSONArray dataList = JSONObject.parseArray(rowData);
			// 获取需要更新的原材料编号。
		    Map<String, JSONObject> userMap = new HashMap<String, JSONObject>();
		    String bms = "";
			List<String> bhList = new ArrayList<>();
			for (int i = 0; i < dataList.size(); i++) {
				JSONObject jsonObject = (JSONObject) dataList.get(i);
				String bm = (String) jsonObject.get("CLBM");
				//String status = (String) jsonObject.get("STATUS");

					JSONObject json = new JSONObject();
					json.put("CLDJ", (String) jsonObject.get("BHSCGJ"));					
					json.put("MC", (String) jsonObject.get("CLMC"));
					json.put("LX", (String) jsonObject.get("LX"));
					json.put("DW", (String) jsonObject.get("CLDW"));
					json.put("XH", (String) jsonObject.get("GG"));
					json.put("BM", bm);
					bhList.add(bm);
					userMap.put(bm, json);
					if (bms.isEmpty()) {
						bms = "'" + bms + "'";
					} else {
						bms += ",'" + bms + "'";
					}
			

			}
			/**
			 * 1、获取需要更新的制造件信息
			 */
		Map<String, JSONObject> comtMap=RefreshDataUtils.getManufacturedPart(userMap);
			/**
			 * 2、获取需要更新的装配件信息
			 */
		Map<String, JSONObject> comtMapNew=RefreshDataUtils.getAssembly(comtMap);
		//将更新的物料信息存放在comtMapNew中
		if(comtMap.size()>0) {
			for (String  key : comtMap.keySet()) {
				comtMapNew.put(key, comtMap.get(key));
			}
		}
		
		
			/**
			 * 3、获取需要更新的模块信息
			 * 
			 */
		Map<String, Map<String, Object>> modulLists=RefreshModulDataUtils.getPorpertiesModule(comtMapNew);
			/**
			 * 4、获取需要更新的项目报价记录台账中类型为模板的数据
			 * 
			 */
		RefreshTempDataUtils.upateTempByPorperties(modulLists);
		ResponseObject ro = ResponseObject.newOkResponse();
		return ro.toString();
		} catch (Exception e) {
			throw e;
		}
		
	}

}
